package org.apache.doris.demo.spring.controller;

import org.apache.doris.demo.spring.model.Tag;
import org.apache.doris.demo.spring.service.DorisTtestSinkService;
import org.apache.doris.demo.spring.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tag")
public class tagController {

    @Autowired
    private TagService tagService;



    @GetMapping("list")
    public Map<String,Object> getList(){
       List<Tag> tagList=  tagService.list();
       return Succeed(tagList);
    }


    @GetMapping("DataCount")
    public Map<String,Object> DataCount(){
       Map<String,Object> tagList=  tagService.DataCount();
       return Succeed(tagList);
    }

    @GetMapping("getremen")
    public Map<String,Object> getremen(){
       List<Map<String,Object>> tagList=  tagService.getremen();
       return Succeed(tagList);
    }

    @GetMapping("getpaihang")
    public Map<String,Object> getpaihang(){
       List<Map<String,Object>> tagList=  tagService.getpaihang();
       return Succeed(tagList);
    }

    @PostMapping("add")
    public Map<String,Object> addTag(Tag tag){
       return       tores(tagService.save(tag));
    }

    public Map<String,Object> Succeed(Object o){
        Map<String,Object> map=new HashMap<>();
        map.put("code",200);
        map.put("msg","操作成功");
        map.put("data",o);
        return map;
    }

    public Map<String,Object> error(){
        Map<String,Object> map=new HashMap<>();
        map.put("code",500);
        map.put("msg","操作失败");
        return map;
    }
    public Map<String,Object> tores(Boolean bo){
        if (bo){
            return Succeed(null);
        }else {
            return error();
        }
    }



}
